package handler

import (
	"github.com/gin-gonic/gin"
	"social-hub/models"
	"social-hub/pkg"
)

func Register(c *gin.Context) {
	username := c.PostForm("tel")
	password := c.PostForm("password")
	data := models.User{

		Tel:      username,
		Password: pkg.Md5(password),
	}
	if err := models.DB.Create(&data).Error; err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "注册失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "注册成功",
	})
	return
}
